{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[Sebastian Raschka](http://sebastianraschka.com), 2016\n",
    "\n",
    "https://github.com/rasbt/python-machine-learning-book"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that the optional watermark extension is a small IPython notebook plugin that I developed to make the code reproducible. You can just skip the following line(s)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sebastian Raschka 2016-03-23 \n",
      "\n",
      "CPython 3.5.1\n",
      "IPython 4.0.3\n",
      "\n",
      "scikit-learn 0.17.1\n",
      "numpy 1.10.4\n",
      "scipy 0.17.0\n"
     ]
    }
   ],
   "source": [
    "%load_ext watermark\n",
    "%watermark -a 'Sebastian Raschka' -v -d -p scikit-learn,numpy,scipy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# to install watermark just uncomment the following line:\n",
    "#%install_ext https://raw.githubusercontent.com/rasbt/watermark/master/watermark.py"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bonus Material - Scikit-learn Model Persistence using JSON"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In many situations, it is desirable to store away a trained model for future use. These situations where we want to persist a model could be the deployment of a model in a web application, for example, or scientific reproducibility of our experiments."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "I [wrote](http://nbviewer.jupyter.org/github/rasbt/python-machine-learning-book/blob/master/code/ch09/ch09.ipynb#Serializing-fitted-scikit-learn-estimators) a little bit about serializing scikit-learn models using `pickle` in context of the web applications that we developed in chapter 8. Also, you can find an excellent [tutorial section](http://scikit-learn.org/stable/modules/model_persistence.html) on scikit-learn's website. Honestly, I would say that pickling Python objects via the [`pickle`](https://docs.python.org/3.5/library/pickle.html), [`dill`](https://pypi.python.org/pypi/dill) or [`joblib`](https://pythonhosted.org/joblib/) modules is probably the most convenient approach to model persistence. However, pickling Python objects can sometimes be a little bit problematic, for example, deserializing a model in Python 3.x that was originally pickled in Python 2.7x and vice versa. Also, pickle offers different protocols (currently the protocols `0-4`), which are not necessarily backwards compatible. \n",
    "Thus, to prepare for the worst case scenario -- corrupted pickle files or version incompatibilities -- there's at least one other (a little bit more tedious) way to model persistence using [JSON](http://www.json.org). \n",
    "\n",
    "> JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language. [Source: http://www.json.org]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "One of the advantages of JSON is that it is a human-readable format. So, if push comes to shove, we should still be able to read the parameter files and model coefficients \"manually\" and assign these values to the respective scikit-learn estimator or build our own model to reproduce scientific results."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's see how that works ... First, let us train a simple logistic regression classifier on Iris:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAEKCAYAAAAGvn7fAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8VOX1+PHPSSYJZCGBgCEEiCwiBaIsRbCixlKrtS6t\n1Sr9WbT6U74ubVWqtVJbFcGlYuuGRaVWS6Wt/VYpirWtQhWrApIoEQEhsiUBgUDIQpJJ8nz/mMkw\nCXNnSeZmtvN+vfIKc+fOvScBzjxznnOfK8YYlFJKxY+kSAeglFIqvDSxK6VUnNHErpRScUYTu1JK\nxRlN7EopFWc0sSulVJxxRDoA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
       "<matplotlib.figure.Figure at 0x10446de80>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%matplotlib inline\n",
    "from sklearn.linear_model import LogisticRegression \n",
    "from sklearn.datasets import load_iris\n",
    "import matplotlib.pyplot as plt\n",
    "from mlxtend.plotting import plot_decision_regions\n",
    "\n",
    "iris = load_iris()\n",
    "y, X = iris.target, iris.data[:, [0, 2]]  # only use 2 features\n",
    "lr = LogisticRegression(C=100.0, \n",
    "                        class_weight=None, \n",
    "                        dual=False, \n",
    "                        fit_intercept=True,\n",
    "                        intercept_scaling=1, \n",
    "                        max_iter=100, \n",
    "                        multi_class='multinomial', \n",
    "                        n_jobs=1,\n",
    "                        penalty='l2', \n",
    "                        random_state=1, \n",
    "                        solver='newton-cg', \n",
    "                        tol=0.0001,\n",
    "                        verbose=0, \n",
    "                        warm_start=False)\n",
    "lr.fit(X, y)\n",
    "plot_decision_regions(X=X, y=y, clf=lr, legend=2)\n",
    "plt.xlabel('sepal length')\n",
    "plt.ylabel('petal length')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Luckily, we don't have to retype or copy & paste all the estimator parameters manually if we want to store them away. To get a dictionary of these parameters, we can simply use the handy \"get_params\" method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'C': 100.0,\n",
       " 'class_weight': None,\n",
       " 'dual': False,\n",
       " 'fit_intercept': True,\n",
       " 'intercept_scaling': 1,\n",
       " 'max_iter': 100,\n",
       " 'multi_class': 'multinomial',\n",
       " 'n_jobs': 1,\n",
       " 'penalty': 'l2',\n",
       " 'random_state': 1,\n",
       " 'solver': 'newton-cg',\n",
       " 'tol': 0.0001,\n",
       " 'verbose': 0,\n",
       " 'warm_start': False}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lr.get_params()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Storing them in JSON format is easy, we simply import the `json` module from Python's standard library and dump the dictionary to a file:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "with open('./sckit-model-to-json/params.json', 'w', encoding='utf-8') as outfile:\n",
    "   json.dump(lr.get_params(), outfile)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When we read the file, we can see that the JSON file is just a 1-to-1 copy of our Python dictionary in text format:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"dual\": false, \"max_iter\": 100, \"warm_start\": false, \"verbose\": 0, \"C\": 100.0, \"class_weight\": null, \"random_state\": 1, \"fit_intercept\": true, \"multi_class\": \"multinomial\", \"intercept_scaling\": 1, \"penalty\": \"l2\", \"solver\": \"newton-cg\", \"n_jobs\": 1, \"tol\": 0.0001}\n"
     ]
    }
   ],
   "source": [
    "with open('./sckit-model-to-json/params.json', 'r', encoding='utf-8') as infile:\n",
    "    print(infile.read())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, the trickier part is to identify the \"fit\" parameters of the estimator, i.e., the parameters of our logistic regression model. However, in practice it's actually pretty straight forward to figure it out by heading over to the respective [documentation page](http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html): Just look out for the \"attributes\" in the \"Attribute\" section that have a trailing underscore (thanks, scikit-learn team, for the beautifully thought-out API!). In case of logistic regression, we are interested in the weights `.coef_`, the bias unit `.intercept_`, and the `classes_` and `n_iter_` attributes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['classes_', 'coef_', 'intercept_', 'n_iter_']\n"
     ]
    }
   ],
   "source": [
    "attrs = [i for i in dir(lr) if i.endswith('_') and not i.endswith('__')]\n",
    "print(attrs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "attr_dict = {i: getattr(lr, i) for i in attrs}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In order to deserialize NumPy arrays to JSON objects, we need to cast the arrays to (nested) Python lists first, however, it's not that much of a hassle thanks to the `tolist` method. (Also, consider saving the attributes to separate JSON files, e.g., intercept.json and coef.json, for clarity.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "for k in attr_dict:\n",
    "    if isinstance(attr_dict[k], np.ndarray):\n",
    "        attr_dict[k] = attr_dict[k].tolist()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, we are ready to dump our \"attribute dictionary\" to a JSON file:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('./sckit-model-to-json/attributes.json', 'w', encoding='utf-8') as outfile:    \n",
    "   json.dump(attr_dict, \n",
    "             outfile, \n",
    "             separators=(',', ':'), \n",
    "             sort_keys=True, \n",
    "             indent=4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If everything went fine, our JSON file should look like this -- in plaintext format:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "    \"classes_\":[\n",
      "        0,\n",
      "        1,\n",
      "        2\n",
      "    ],\n",
      "    \"coef_\":[\n",
      "        [\n",
      "            0.42625236403173844,\n",
      "            -8.557501546363858\n",
      "        ],\n",
      "        [\n",
      "            1.5644231337040186,\n",
      "            -1.6783659020502222\n",
      "        ],\n",
      "        [\n",
      "            -1.990675497337773,\n",
      "            10.235867448186507\n",
      "        ]\n",
      "    ],\n",
      "    \"intercept_\":[\n",
      "        27.533384852155145,\n",
      "        4.18509910962595,\n",
      "        -31.71848396177913\n",
      "    ],\n",
      "    \"n_iter_\":[\n",
      "        27\n",
      "    ]\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "with open('./sckit-model-to-json/attributes.json', 'r', encoding='utf-8') as infile:\n",
    "    print(infile.read())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With similar ease, we can now use `json`'s `loads` method to read the data back from the \".json\" files and re-assign them to Python objects. (Imagine the following happens in a new Python session.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import codecs\n",
    "import json\n",
    "\n",
    "obj_text = codecs.open('./sckit-model-to-json/params.json', 'r', encoding='utf-8').read()\n",
    "params = json.loads(obj_text)\n",
    "\n",
    "obj_text = codecs.open('./sckit-model-to-json/attributes.json', 'r', encoding='utf-8').read()\n",
    "attributes = json.loads(obj_text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, we just need to initialize a default `LogisticRegression` estimator, feed it the desired parameters via the `set_params` method, and reassign the other attributes using Python's built-in `setattr` (don't forget to recast the Python lists to NumPy arrays, though!):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAEKCAYAAAAGvn7fAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8VOX1+PHPSSYJZCGBgCEEiCwiBaIsRbCixlKrtS6t\n1Sr9WbT6U74ubVWqtVJbFcGlYuuGRaVWS6Wt/VYpirWtQhWrApIoEQEhsiUBgUDIQpJJ8nz/mMkw\nCXNnSeZmtvN+vfIKc+fOvScBzjxznnOfK8YYlFJKxY+kSAeglFIqvDSxK6VUnNHErpRScUYTu1JK\nxRlN7EopFWc0sSulVJ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text/plain": [
       "<matplotlib.figure.Figure at 0x10a024438>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%matplotlib inline\n",
    "from sklearn.linear_model import LogisticRegression \n",
    "from sklearn.datasets import load_iris\n",
    "import matplotlib.pyplot as plt\n",
    "from mlxtend.plotting import plot_decision_regions\n",
    "import numpy as np\n",
    "\n",
    "iris = load_iris()\n",
    "y, X = iris.target, iris.data[:, [0, 2]]  # only use 2 features\n",
    "lr = LogisticRegression()\n",
    "\n",
    "lr.set_params(**params)\n",
    "for k in attributes:\n",
    "    if isinstance(attributes[k], list):\n",
    "        setattr(lr, k, np.array(attributes[k]))\n",
    "    else:\n",
    "        setattr(lr, k, attributes[k])\n",
    "\n",
    "\n",
    "plot_decision_regions(X=X, y=y, clf=lr, legend=2)\n",
    "plt.xlabel('sepal length')\n",
    "plt.ylabel('petal length')\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
